package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.BaseController.BaseController;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 访问资源管理
 */
@Slf4j
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController extends BaseController {
    @Autowired
    private ResourceService resourceService;

    @PostMapping("/list")
    @ApiOperationSupport(includeParameters = {"resourceDto.resourceType","resourceDto.parentResourceNo"})
    public ResponseResult list(@RequestBody ResourceDto resourceDto){
        List<ResourceVo> list = resourceService.list(resourceDto);
        return success(list);
    }

    @PostMapping("/tree")
    @ApiOperationSupport(includeParameters = {"resourceDto.label"})
    public ResponseResult tree(@RequestBody ResourceDto resourceDto){
      TreeVo treeVo = resourceService.tree(resourceDto);
        return success(treeVo);
    }

    @PutMapping
    @ApiOperation("新增资源")
    public ResponseResult insertResource(@RequestBody ResourceDto resourceDto){
    resourceService.insertResource(resourceDto);
    return  success();
    }

    @DeleteMapping("/{resourceNo}")
    @ApiOperation("删除资源")
    public ResponseResult deleteResource(@PathVariable String resourceNo){
        resourceService.delete(resourceNo);
        return success();
    }

    @PostMapping("/enable")
    @ApiOperation("启用禁用")
    public ResponseResult enable(@RequestBody ResourceDto resourceDto){
        resourceService.enableState(resourceDto);
        return success();
    }


    @PatchMapping
    @ApiOperation("修改资源")
    public ResponseResult update(@RequestBody ResourceDto resourceDto){
        resourceService.update(resourceDto);
        return success();
    }
//    @GetMapping("/menus")
//    @ApiOperation("menus")
//    public ResponseResult menus(){
//        return success();
//    }
}
